package top.yzlin.dblock.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import redis.clients.jedis.JedisPool;

import java.util.concurrent.Executor;

@Configuration
public class MainConfig {
    private Environment environment;

    @Autowired
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }


    @Bean
    public JedisPool jedisPool() {
        String host = environment.getProperty("jedis.url", "localhost");
        int port = Integer.parseInt(environment.getProperty("jedis.port", "6379"));
        return new JedisPool(host, port);
    }

    @Bean
    public Executor executor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10);
        return executor;
    }


}
